package net.jlibrary.common.project.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonBackReference;

import net.jlibrary.common.core.annotation.CodeGenComment;
import net.jlibrary.common.core.annotation.Compositor;
import net.jlibrary.common.core.annotation.SearchCondition;
import net.jlibrary.common.core.annotation.SearchField;
import net.jlibrary.common.core.annotation.SeePurview;
import net.jlibrary.common.core.annotation.ValidateSign;
import net.jlibrary.common.core.entity.BaseObject;
import net.jlibrary.common.core.entity.IGroup;
import net.jlibrary.common.core.entity.IValid;

/**
 * 机构基础表
 * @author sunlf
 *
 */
@Compositor
@SeePurview(value="globalPath")
@ValidateSign(value="sign",validSign="validSign",toException=false)
@Entity(name="tab_group")
@Inheritance(strategy = InheritanceType.JOINED)
public class Group extends BaseObject implements IGroup, IValid {
	private static final long serialVersionUID = -7412023491158604372L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@SearchField(value = "id", condition = SearchCondition.EQUAL)
	private Long id;
	@Column(length = 50)
	@SearchField(value = "code", condition = SearchCondition.EQUAL)
	@CodeGenComment(value = "机构代码", viewList = true, viewSearch = true, required = true)
	private String code;// 机构代码
	@Column(length = 100)
	@SearchField(value = "globalPath", condition = SearchCondition.FUZZ_RIGHT)
	private String globalPath;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id")
	@SearchField(value = "parentGroup", condition = SearchCondition.EQUAL)
	@CodeGenComment(value = "上级代码", viewList = true, viewSearch = true)
	@JsonBackReference
	private Group parentGroup;// 上级机构
	//==========================================================//
	
	@Column(length = 100)
	@CodeGenComment(value = "机构全称", viewList = true, viewSearch = true ,maxLength=50)
	@SearchField(value = "fullName", condition = SearchCondition.FUZZ_FULL)
	private String fullName;// 机构全称
	@Column(length = 100)
	@CodeGenComment(value = "企业简称", viewList = true, viewSearch = true ,viewText=true,minLength=5,maxLength=50)
	private String shortName;// 企业简称
	@CodeGenComment(value = "有效性", viewList = true, viewSearch = true)
	private boolean valid;
	@Column(updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@CodeGenComment(value = "创建时间", viewList = true)
	private Date createdate;
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastdate;
	
	@Transient
	private boolean allowQueryInvalid;
	@Transient
	private boolean compellingDelete;
	
	@Column(length = 10)
	@CodeGenComment(value = "登录模式", viewList = true)
	private String loginMode;//登录模式

	public Long getId() {
		return id;
	}
	
	@Override
	@Transient
	public Serializable getPrimaryKey() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getGlobalPath() {
		return globalPath;
	}

	public void setGlobalPath(String globalPath) {
		this.globalPath = globalPath;
	}

	public Group getParentGroup() {
		return parentGroup;
	}

	public void setParentGroup(Group parentGroup) {
		this.parentGroup = parentGroup;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	public boolean isAllowQueryInvalid() {
		return allowQueryInvalid;
	}

	public void setAllowQueryInvalid(boolean allowQueryInvalid) {
		this.allowQueryInvalid = allowQueryInvalid;
	}

	public boolean isCompellingDelete() {
		return compellingDelete;
	}

	public void setCompellingDelete(boolean compellingDelete) {
		this.compellingDelete = compellingDelete;
	}
	
	@Override
	public Date getCreatedate() {
		return createdate;
	}

	@Override
	public Date getLastdate() {
		return lastdate;
	}

	@Override
	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	@Override
	public void setLastdate(Date lastdate) {
		this.lastdate = lastdate;
	}

	public boolean equals(Object rhs) {
		if (rhs == null)
			return false;
		if (!(rhs instanceof Group))
			return false;
		Group that = (Group) rhs;
		if (this.getId() == null || that.getId() == null)
			return false;
		return (this.getId().equals(that.getId()));
	}

	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	public String getLoginMode() {
		return loginMode;
	}

	public void setLoginMode(String loginMode) {
		this.loginMode = loginMode;
	}
}
